package cheesymock.recorder;

public class ArgumentModifier<T> {
	private Integer argumentIndex = null;
	private final ArgumentComparator<T> comparator;
	private final T expectedValue;

	public ArgumentModifier(ArgumentComparator<T> comparator, int argumentIndex) {
		this.argumentIndex = argumentIndex;
		this.comparator = comparator;
		this.expectedValue = null;
	}

	public ArgumentModifier(T expectedValue, ArgumentComparator<T> comparator) {
		this.expectedValue = expectedValue;
		this.comparator = comparator;
	}

	/**
	 * The caller of this method must catch ClassCastException, since the ArgumentComparator could
	 * be typed with an illegal subclass.
	 *
	 * @param actualArgument
	 * @return
	 */
	@SuppressWarnings("unchecked")
	boolean equalArgument(Object actualArgument) {
		return comparator.compare((T) actualArgument, expectedValue);
	}

	T getArgument() {
		return expectedValue;
	}

	Integer getArgumentIndex() {
		return argumentIndex;
	}

	void setArgumentIndex(int argumentIndex) {
		this.argumentIndex = argumentIndex;
	}
}
